package com.topvision.controller.hes;

import java.util.List;
import java.util.Map;

import com.topvision.controller.AbstractController;
import com.topvision.model.region.Region;
import com.topvision.service.region.RegionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.model.hes.HesExpert;
import com.topvision.service.hes.HesExpertService;
import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;

/**
 * 专家用户
 *
 * @author shengwm
 * @email 179653076@qq.com
 * @date 2017-08-30 14:27:46
 */
@RestController
@RequestMapping("hes/hesexpert")
public class HesExpertController extends AbstractController {
    @Autowired
    private HesExpertService hesExpertService;
    @Autowired
    private RegionService regionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("hes/hesexpert:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<HesExpert> hesExpertList = hesExpertService.queryList(query);
        int total = hesExpertService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(hesExpertList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("hes/hesexpert:info")
    public R info(@PathVariable("id") Long id){
        HesExpert hesExpert = hesExpertService.queryObject(id);
        return R.success().put("hesExpert", hesExpert);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("hes/hesexpert:save")
    public R save(@RequestBody HesExpert hesExpert){
		hesExpertService.save(hesExpert);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("hes/hesexpert:update")
    public R update(@RequestBody HesExpert hesExpert){
		hesExpertService.update(hesExpert);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("hes/hesexpert:delete")
    public R delete(@RequestBody Long[] ids){
		hesExpertService.deleteBatch(ids);
        return R.success();
    }

    /**
     * 所有城市数据
     */
    @RequestMapping("/regionlist")
    public R regionlist(){
        List<Region> regionList = regionService.findAll();
        return R.success().put("region",regionList);
    }

    /**
     * 所有省份数据
     */
    @RequestMapping("/provinces")
    public R provinces(){
        List<Region> regionList = regionService.provinces();
        return R.success().put("provinces",regionList);
    }

    /**
     * 所有城市数据
     */
    @RequestMapping("/cities/{provinceid}")
    public R cities(@PathVariable("provinceid") Long provinceid){
        List<Region> regionList = regionService.cities(provinceid);
        return R.success().put("cities",regionList);
    }

}
